#include "sort.h"



#define NUM 40

int x[NUM] = { 0 };
int x1[NUM] = { 0 };
int x2[NUM] = { 0 };
int x3[NUM] = { 0 };
int x4[NUM] = { 0 };

void test()
{
	
	srand((unsigned)time(NULL));
	for (int i = 0; i < NUM; i++)
	{
		x[i] = rand() % 100;
		x1[i] = x[i];
		x2[i] = x[i];
		x3[i] = x[i];
		x4[i] = x[i];
		printf("\r%.2f%c", (i + 1) * 1.0 / NUM * 100, '%');
	}
	printf("\n");
	int begin[5] = { 0 };
	int end[5] = { 0 };
	begin[0] = clock();
	BubbleSort(x, sizeof(x)/sizeof(x[0]));
	end[0] = clock();
	printf("BubbleSort End\n");
	begin[1] = clock();
	InsertSort(x1, sizeof(x1) / sizeof(x1[0]));
	end[1] = clock();
	printf("InsertSort End\n");
	begin[2] = clock();
	ShellSort(x2, NUM);
	end[2] = clock();
	printf("ShellSort End\n");
	begin[3] = clock();
	HeapSort(x3, sizeof(x3) / sizeof(x3[0]));
	end[3] = clock();
	printf("HeapSort End\n");
	begin[4] = clock();
	PartSort1(x4, 0, sizeof(x4) / sizeof(x4[0]) - 1);
	end[4] = clock();
	printf("PartSort1 End\n");
	for (int i = 0; i < NUM; i++)
	{
		printf("%d ", x[i]);
	}
	printf("\n");
	printf("\n");

	for (int i = 0; i < NUM; i++)
	{
		printf("%d ", x1[i]);
	}
	printf("\n");
	printf("\n");

	for (int i = 0; i < NUM; i++)
	{
		printf("%d ", x2[i]);
	}
	printf("\n");
	printf("\n");

	for (int i = 0; i < NUM; i++)
	{
		printf("%d ", x3[i]);
	}
	printf("\n");
	printf("\n");

	for (int i = 0; i < NUM; i++)
	{
		printf("%d ", x4[i]);
	}
	printf("\n");
	printf("\n");

	printf("BubbleSort : %d\n", end[0] - begin[0]);
	printf("InsertSort : %d\n", end[1] - begin[1]);
	printf("ShellSort : %d\n", end[2] - begin[2]);
	printf("HeapSort : %d\n", end[3] - begin[3]);
	printf("PartSort1 : %d\n", end[4] - begin[4]);

}


void Test()
{
	int a1[50] = { 0 };
	int a2[50] = { 0 };
	int suc = 10000;
	for (int j = 0; j < 10000;j++)
	{
		for (int i = 0; i < 40; i++)
		{
			a1[i] = rand() % 100;
			a2[i] = a1[i];
		}
		HeapSort(a1, 50);
		ShellSort(a2, 50);
		for (int i = 0; i < 40; i++)
		{
			printf("%d ", a1[i]);
		}
		printf("\n");
		for (int i = 0; i < 40; i++)
		{
			printf("%d ", a1[i]);
		}
		printf("\n");
		Sleep(1000);
		for (int i = 0; i < 40; i++)
		{
			if (a1[i] != a2[i])
			{
				suc--;
				break;
			}
		}
	}
	printf("%d\n", suc);
	printf("%.2f%c\n", suc * 100.0 / 10000, '%');
}


int main()
{
	test();
	//Test();
	return 0;
}